<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>抹掉数组中的0</title>
</head>
<body>
    <script>
        var arr = [2, 0, 23, 0, 5, 11, 0, 20];
        var newArr = [];
        for (var i = 0; i < arr.length; i++) {
            // 方法1
            // if (arr[i] == 0) {
            //     continue;
            // } else {
            //     newArr[newArr.length] = arr[i]
            // }
            // 方法2
            if (arr[i] != 0) {
                newArr[newArr.length] = arr[i]
            }
        }
        console.log(newArr);
    </script>
</body>
</html>